<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@include file='checkLoggedIn.jsp'%>
<%@include file='templates/header.jsp'%>
<%@ page import="awesome.Manager.ItemManager"%>
<%@ page import="java.util.LinkedList"%>
<%@	page import="awesome.Manager.Item"%>

<!-- Title -->
<table>
	<tr>
		<td width='500' align="center">
		<h1>My Bids</h1>
		</td>
	</tr>
</table>

<BR>

<!-- Column Labels -->
<table CELLSPACING="10">
	<tr>
		<td width='262' align="center"><B></B></td> <!-- No label for item name -->
		<td width='75' align="center"><B></B></td> <!-- No label for # of bids -->
		<td width='75' align="center"><B>Your Bid</B></td>
		<td width='75' align="center"><B>Highest Bid</B></td>
		<td width='100' align="center"><B>Ends</B></td>
	</tr>
</table>

<HR width='625' align="left">

<!-- Table with row information -->
<table CELLSPACING="10">

	<%
		int uid = Integer.parseInt(session.getAttribute("uid").toString());
		
	
		ItemManager im = new ItemManager();
		LinkedList l = im.getItemsByBidder(uid);
		System.out.println("In myBids.jsp");

		for (int i = 0; i < l.size(); i++) {
			
			Item item = (Item) (l.get(i));
			int id = ((Item) (l.get(i))).getItemID();
			
			//URL for the item's page
			String url = "view_item.jsp?iid="+id; 
			
			//format the user's bid properly
			String userBid = im.getBidOfUser(id, uid) + "";
			if (userBid.indexOf(".") == userBid.length() - 2)
				userBid = userBid + "0";
			
			//format the highest bid properly
			String price = im.getHighestBid(id) + "";
			if (price.indexOf(".") == price.length() - 2)
				price = price + "0";

			//for testing only - need to set actual image path
			item.setImagePath("http://i38.photobucket.com/albums/e127/ImmuneEntity/Bluehills75.jpg");

			out.println("<tr>");

			//Item Picture
			out.println("<td width='75' align=\"left\"><a href=\"" + url
					+ "\"> <img src=\"" + item.getImagePath()
					+ "\" width=\"75\" height=\"75\"></td>");
			
			//Item Name
			out.println("<td width='175' align=\"left\"> <a href=\"" + url
					+ " \">" + item.getName() + "</a></td>");
			
			//Number of Bids
			out.println("<td width='75' align=\"center\">"
					+ im.getNumBids(id) + " Bids</td>");
			
			//User's Bid
			out.println("<td width='75' align=\"center\"> $" + userBid
					+ "</td>");
			
			//Highest Bid
			out.println("<td width='75' align=\"center\"> $" + price
					+ "</td>");
			
			//End Date
			out.println("<td width='100' align=\"center\">"
					+ item.getEndTime() + "</td>");

			out.println("</tr>");

		}
	%>

</table>

<%@include file='templates/footer.jsp'%>